#ifndef __DOUBLELINKLIST_H_
#define __DOUBLELINKLIST_H_

class DoubleLinkList
{
public:
using ElementType = void*;
public:
    DoubleLinkList();



    void SetPrint(void (*print)(ElementType))
    {
        this->Print = print;
    }

    void SetCompare(bool(*compare)(ElementType,ElementType))
    {
        this->Compare = compare;
    }
    void SetFreeptr(void (*freeptr)(ElementType))
    {
        this->Freeptr = freeptr;
    }



    void InsertTail(const ElementType&element);
    
    void InsertHead(const ElementType&element);


    // 中间插入
    void InsertByIndex(int index,const ElementType &element);

    
    // 按位置删
    void RemoveByIndex(int index);  

    // 按值删
    void RemoveElement(const ElementType&element);

    // void* 回调用


    ~DoubleLinkList();

    void show();


    int Size()
    {
        return this->size;
    }

    ElementType* Back()
    {
        return & tail->data;
    }

    ElementType* Head()
    {
        return &head->next->data;
    }




private:
    struct Node
    {
        Node(const ElementType &data):data(data),prev(nullptr),next(nullptr){}
        ElementType data;
        Node*next;
        Node*prev;//前置指针

    };
    
    Node* head;//头指针
    Node* tail;//尾指针
    int size;
    
    void (*Print)(ElementType);
    bool (*Compare)(ElementType,ElementType);
    void (*Freeptr)(ElementType);
};


#endif